Public Class NewCustomerDialog
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents lblErr As System.Web.UI.WebControls.Label
    Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Protected WithEvents UserControl1 As UserControl

    Private CUSTOMER_USER_PAGEBO_SESSION_NAME As String = "MIMS_WRS.Web.CustomerUser.PageBO"

    Protected Property PageBO() As CUser
        Get
            Return CType(Session(Me.CUSTOMER_USER_PAGEBO_SESSION_NAME), CUser)
        End Get
        Set(ByVal Value As CUser)
            Session(Me.CUSTOMER_USER_PAGEBO_SESSION_NAME) = Value
        End Set
    End Property

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then

            Dim obj As New CUser

            obj.Init()
            obj.UserType = 0 'customer

            Me.PageBO = obj
            Me.UserControl1.PageBOSessionName = Me.CUSTOMER_USER_PAGEBO_SESSION_NAME
            Me.UserControl1.PopupTitleEnabled = True

        End If
    End Sub

    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Try
            Me.UserControl1.UpdateData()
            PageBO.Save()
            Me.SetReturnValue()
        Catch ex As Exception
            Me.lblErr.Text = ex.Message
        End Try
    End Sub

    Private Sub SetReturnValue()
        Dim s As String = ""
        s += "var obj= new Object();"
        s += String.Format("obj.ID = '{0}';", PageBO.UsIdPk)
        s += String.Format("obj.Name = ""{0}"";", HttpUtility.UrlEncode(PageBO.Name))
        s += "window.returnValue = obj;"
        s += "window.close();"
        Response.Write(String.Format("<script>{0}</script", s))
    End Sub
End Class
